﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.Cust.YYD.PlugBE.Dtos;
using UFIDA.U9.Cust.YYD.PlugBE.Public;
using UFIDA.U9.MO.MO;
using UFIDA.U9.PM.Rcv;
using UFSoft.UBF.Business;

namespace UFIDA.U9.Cust.YYD.PlugBE.MOPickListP
{
    public class AfterUpdating : UFSoft.UBF.Eventing.IEventSubscriber
    {
        public void Notify(params object[] args)
        {
            #region 从事件参数中取得当前业务实体													 
            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
                return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
                return;
            var holder = key.GetEntity() as UFIDA.U9.MO.MO.MOPickList;
            if (holder == null)
                return;
            #endregion
            //开工
            if (holder.MO.DocState == MO.Enums.MOStateEnum.Released && MOPickIsChange(holder.OriginalData, holder))
            {
                throw new Exception("生产开工后不允许修改备料");
            }
        }

        public bool MOPickIsChange(MOPickList.EntityOriginal a, MOPickList b)
        {

            if (a.ItemMaster.ID != b.ItemMaster.ID ||
                a.ActualReqQty != b.ActualReqQty||
                a.Project != b.Project ||
                a.SupplyWh != b.SupplyWh ||
                a.PlanReqDate != b.PlanReqDate)
            {
                return true;
            }

            return false;
        }
    }
}
